<?php

namespace App\CompanyApi\Resources;

use App\Models\JobpositionModel;
use Illuminate\Http\Resources\Json\JsonResource;
use SuperEggs\DcatDistpicker\DcatDistpickerHelper;

class JobpositionDetailResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'position_name' => $this->position_name,
            'region_province' => $this->region_province,
            'region_city' => $this->region_city,
            'region_region' => $this->region_region,
            'salary' => $this->salary,
            'salary_type' => $this->salary_type,
            'gender_requirement' => $this->gender_requirement,
            'min_age' => $this->min_age,
            'max_age' => $this->max_age,
            'selection_date_start' => $this->selection_date_start,
            'selection_date_end' => $this->selection_date_end,
            'work_time_start' => $this->work_time_start,
            'work_time_end' => $this->work_time_end,
            'work_experience' => $this->work_experience,
            'job_description' => $this->job_description,
            'contact_type' => $this->contact_type,
            'contactPhone' => $this->contactPhone($this->contactPhone),
            'contactQq' => $this->contactQq($this->contactQq),
            'contactWechat' => $this->contactWechat($this->contactWechat),
        ];
    }

    private function contactPhone($contactPhone)
    {
        $res = [];
        foreach ($contactPhone as $phone) {
            $res[] = [
                'id' => $phone->id,
                'phone_number' => $phone->phone_number,
                'number' => $phone->number,
                'recruit_num' => $phone->recruit_num,
            ];
        }
        return $res;
    }

    private function contactQq($contactQq)
    {
        $res = [];
        foreach ($contactQq as $qq) {
            $res[] = [
                'id' => $qq->id,
                'qq_number' => $qq->qq_number,
                'qq_qr_code' => $qq->qq_qr_code,
                'number' => $qq->number,
                'recruit_num' => $qq->recruit_num,
            ];
        }
        return $res;
    }

    private function contactWechat($contactWechat)
    {
        $res = [];
        foreach ($contactWechat as $wechat) {
            $res[] = [
                'id' => $wechat->id,
                'wechat_number' => $wechat->wechat_number,
                'wechat_qr_code' => $wechat->wechat_qr_code,
                'number' => $wechat->number,
                'recruit_num' => $wechat->recruit_num,
            ];
        }
        return $res;
    }
}
